Skip to content

Conversation

@minnur
Copy link
Contributor

@minnur minnur commented Jan 15, 2025

This pull request is for: (mark with an "x")

  • examples/*
  • modules/next
  • packages/next-drupal
  • starters/basic-starter
  • starters/graphql-starter
  • starters/pages-starter
  • Other

GitHub Issue: #812

  • I need help adding tests.

Describe your changes

Added new cache tag revalidator plugin to the next module.

@vercel
Copy link

vercel bot commented Jan 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-drupal-next ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2025 4:26pm
2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
next-drupal ⬜️ Ignored (Inspect) Visit Preview Jan 17, 2025 4:26pm
next-drupal-v1-6 ⬜️ Ignored (Inspect) Visit Preview Jan 17, 2025 4:26pm

@vermario
Copy link

I was able to confirm that the tags are correctly passed to the frontend.
I tried using this version of the module with our starterkit in a local copy, adapting the route at api/revalidate:

image

$tags[] = $entity->getEntityTypeId() . '_list';
$tags[] = $entity->getEntityTypeId() . '_list:' . $entity->bundle();
}
$cache_tags = implode(',', $entity->getCacheTags());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@minnur I think the entity list tags we still have to add manually, at least in my test for nodes for example $entity->getCacheTags only gave node:8

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't know about this, but apparently if we do this:

$entity->getEntityType()->getListCacheTags();

We should get the correct list tag. The one with the bundle at the end we still need to create manually.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find! I added that to the plugin. See db2690b
I noticed $entity->getEntityType()->getListCacheTags(); does not have entity_type_list:bundle. So I looked at \Drupal\Entity\EntityBase class and found a method getListCacheTagsToInvalidate() that adds that to the invalidation list and implemented the same logic in the plugin.

Copy link
Member

@robdecker robdecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 LGTM

Comment on lines +60 to +65
$list_tags = $entity->getEntityType()->getListCacheTags();
if ($entity->getEntityType()->hasKey('bundle')) {
$list_tags[] = $entity->getEntityTypeId() . '_list:' . $entity->bundle();
}
$combined_tags = array_merge($entity->getCacheTags(), $list_tags);
$cache_tags = implode(',', $combined_tags);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. It is much more concise than our original version.

@backlineint backlineint merged commit 6178aeb into main Jan 22, 2025
6 of 17 checks passed
@backlineint backlineint deleted the 812-invalidation-by-cache-tag branch January 22, 2025 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants